package com.jy.modules.cims.sysUtils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.jy.modules.cims.common.sysUtils.InteractUtil;
import com.jy.modules.cims.data.common.dto.TCMmQuotaLoanDetailDTO;
import com.jy.modules.cims.data.interact.core.loan.response.LoanInfo;

public class LoanDtoConverter {
	private LoanDtoConverter(){};
	private static class Singletonholder{
		private static LoanDtoConverter instance = new LoanDtoConverter();
	}
	public static LoanDtoConverter getInstance(){
		return Singletonholder.instance;
	}
	
	public List<TCMmQuotaLoanDetailDTO> convert(List<LoanInfo>src) throws ParseException{
		List<TCMmQuotaLoanDetailDTO>list=new ArrayList<TCMmQuotaLoanDetailDTO>(src.size());
		for(LoanInfo loan:src){
			TCMmQuotaLoanDetailDTO dest=new TCMmQuotaLoanDetailDTO();
			this.setValues(dest,loan);
			list.add(dest);
		}
		return list;
	}
	
	public TCMmQuotaLoanDetailDTO convert(LoanInfo src) throws ParseException{
		TCMmQuotaLoanDetailDTO dest=new TCMmQuotaLoanDetailDTO();
		this.setValues(dest, src);
		return dest;
	}
	private void setValues(TCMmQuotaLoanDetailDTO dest,LoanInfo loan) throws ParseException{
		dest.setAuditRate(loan.getAuditRate());
		dest.setContractAmount(loan.getContractAmount());
		dest.setContractNo(loan.getContractNo());
		dest.setCooperorgCode(loan.getCorpBrchCode());
		dest.setDefaultInstRate(loan.getDefaultInstRate());
		
		dest.setEndDate(InteractUtil.convert2Date(loan.getEndDate()));
		dest.setFundDate(InteractUtil.convert2Date(loan.getFundDate()));
		
		dest.setLoanAcctName(loan.getLoanAcctName());
		dest.setLoanAcctNo(loan.getLoanAcctNo());
		dest.setLoanAmount(loan.getLoanAmount());
		dest.setLoanBankCode(loan.getLoanBankCode());
		dest.setLoanPeriod(loan.getLoanPeriod());
		dest.setLoanPurpose(loan.getLoanPurpose());
		dest.setManageRate(loan.getManageRate());
		dest.setMonthCompositeRate(loan.getMonthCompositeRate());
		dest.setMonthRate(loan.getMonthRate());
		dest.setOrgId(loan.getOrgId());
		dest.setOrgName(loan.getOrgName());
		dest.setPenaltyInstRate(loan.getPenaltyInstRate());
		dest.setProductCode(loan.getProductCode());
		dest.setProductName(loan.getProductName());
		dest.setQuiryRate(loan.getQuiryRate());
		dest.setRepayAcctName(loan.getRepayAcctName());
		dest.setRepayAcctNo(loan.getRepayAcctNo());
		dest.setRepayBankCode(loan.getRepayBankCode());
		
		dest.setRepayDay(new Integer(loan.getRepayDay()).toString()); // 去零处理
		dest.setRepayType(loan.getRepayType());
		dest.setTotalFee(loan.getTotalFee());
		dest.setQuotaCode(loan.getCreditCode());
		dest.setCustCode(loan.getCustCode());
		
		dest.setFirstPaybackDate(InteractUtil.convert2Date(loan.getFirstPaybackDate()));
        dest.setPaybackAmount(loan.getPaybackAmount());
	}
}
